package com.mxpio.erp.equipment.controller;

import com.mxpio.erp.common.equipment.entity.EquipmentCheckPlan;
import com.mxpio.erp.common.equipment.service.EquipmentCheckPlanDetailService;
import com.mxpio.erp.common.equipment.service.EquipmentCheckPlanService;
import com.mxpio.erp.common.equipment.service.EquipmentCheckPlanTargetService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;

 /**
 * @Description: 点巡检计划
 * @Author: jeecg-boot
 * @Date:   2021-09-16
 * @Version: V1.0
 */
@Tag(name = "EquipmentCheckPlanController", description = "点巡检计划")
@RestController
@RequestMapping("/erp/equipment/spotcheck/tpmCheckPlan")
@Slf4j
public class EquipmentCheckPlanController {

	@Autowired
	private EquipmentCheckPlanService equipmentCheckPlanService;

	@Autowired
	private EquipmentCheckPlanTargetService equipmentCheckPlanTargetService;

	@Autowired
	private EquipmentCheckPlanDetailService equipmentCheckPlanDetailService;


	/*---------------------------------主表处理-begin-------------------------------------*/

	/**
	 * 分页列表查询
	 * @param pageNo
	 * @param pageSize
	 * @param criteria
	 * @return
	 */
	@GetMapping(value = "/page")
    @Operation(summary = "点巡检计划-分页列表查询", description = "点巡检计划-分页列表查询", method = "GET")
	public Result<?> queryPageList(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                   Criteria criteria) {
        Pageable page = PageRequest.of(pageNo-1, pageSize);
        Page<EquipmentCheckPlan> pageList = equipmentCheckPlanService.listPage(EquipmentCheckPlan.class,page, criteria);
        return Result.OK(pageList);
	}

	/**
     *   添加
     * @param equipmentCheckPlan
     * @return
     */
    @PostMapping(value = "/add")
    @Operation(summary = "点巡检计划-添加", description = "点巡检计划-添加", method = "POST")
    public Result<?> add(@RequestBody EquipmentCheckPlan equipmentCheckPlan) {
        equipmentCheckPlan.setLastPlanStart(new Date());
        equipmentCheckPlanService.save(equipmentCheckPlan);
        return Result.OK("添加成功！");
    }

    /**
     *  编辑
     * @param equipmentCheckPlan
     * @return
     */
    @PutMapping(value = "/edit")
    @Operation(summary = "点巡检计划-编辑", description = "点巡检计划-编辑", method = "PUT")
    public Result<?> edit(@RequestBody EquipmentCheckPlan equipmentCheckPlan) {
        equipmentCheckPlanService.update(equipmentCheckPlan);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     * @param id
     * @return
     */
    @DeleteMapping(value = "/delete")
    @Operation(summary = "点巡检计划-通过id删除", description = "点巡检计划-通过id删除", method = "DELETE")
    public Result<?> delete(@RequestParam(name="id",required=true) String id) {
        equipmentCheckPlanService.delMain(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping(value = "/deleteBatch")
    @Operation(summary = "点巡检计划-批量删除", description = "点巡检计划-批量删除", method = "DELETE")
    public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
        this.equipmentCheckPlanService.delBatchMain(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

//    /**
//     * 导出
//     * @return
//     */
//    @RequestMapping(value = "/exportXls")
//    public ModelAndView exportXls(HttpServletRequest request, EquipmentCheckPlan equipmentCheckPlan) {
//        return super.exportXls(request, equipmentCheckPlan, EquipmentCheckPlan.class, "点巡检计划");
//    }
//
//    /**
//     * 导入
//     * @return
//     */
//    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
//    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
//        return super.importExcel(request, response, EquipmentCheckPlan.class);
//    }
	/*---------------------------------主表处理-end-------------------------------------*/


}
